home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / MenuFrame / MenuFrame.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  6.7 KB  |  268 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Frame;
  6. import java.awt.Menu;
  7. import java.awt.MenuBar;
  8. import java.awt.MenuItem;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import java.net.MalformedURLException;
  12. import java.net.URL;
  13. import java.net.URLEncoder;
  14. import java.util.EventObject;
  15.  
  16. public class MenuFrame extends Applet implements ActionListener {
  17.    // $FF: renamed from: wi int
  18.    private int field_0;
  19.    // $FF: renamed from: he int
  20.    private int field_1;
  21.    private MenuBar pop;
  22.    private AudioClip sound;
  23.    private AudioClip clicSound;
  24.    private boolean loopSound;
  25.    private Frame frame;
  26.    private int frameWidth = 300;
  27.    private int frameHeight = 67;
  28.    private int frameX = 400;
  29.    private int frameY = 300;
  30.  
  31.    public String getAppletInfo() {
  32.       return "Name: MenuFrame\r\nAuthor: Taiji Software\r\n";
  33.    }
  34.  
  35.    public void register() {
  36.       try {
  37.          URL u = new URL("http://www.taijisoftware.com");
  38.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  39.       } catch (Exception e) {
  40.          System.out.println(e);
  41.          this.stop();
  42.       }
  43.    }
  44.  
  45.    public void init() {
  46.       String codeBase = null;
  47.  
  48.       try {
  49.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  50.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  51.          codeBase = codeBase.toUpperCase();
  52.       } catch (Exception var9) {
  53.       }
  54.  
  55.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  56.          String regCode = ((Applet)this).getParameter("registration_code");
  57.          if (regCode == null) {
  58.             regCode = ((Applet)this).getParameter("reg_domain");
  59.             if (regCode == null) {
  60.                this.register();
  61.             } else {
  62.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  63.                   codeBase = "WWW." + codeBase;
  64.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  65.                   codeBase = codeBase.substring(4);
  66.                }
  67.  
  68.                char[] chars = new char[codeBase.length()];
  69.                codeBase.getChars(0, codeBase.length(), chars, 0);
  70.                String key = new String("haricot");
  71.                char[] chars2 = new char[key.length()];
  72.                key.getChars(0, key.length(), chars2, 0);
  73.  
  74.                for(int i = 0; i < codeBase.length(); ++i) {
  75.                   int j;
  76.                   if (i >= key.length()) {
  77.                      j = i - key.length() * (i / key.length());
  78.                   } else {
  79.                      j = i;
  80.                   }
  81.  
  82.                   chars[i] += chars2[j];
  83.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  84.                }
  85.  
  86.                String res = new String(chars);
  87.                if (!res.equalsIgnoreCase(regCode)) {
  88.                   this.register();
  89.                }
  90.             }
  91.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  92.             this.register();
  93.          }
  94.       }
  95.  
  96.       this.getParameters();
  97.       this.pop = new MenuBar();
  98.       this.giveMenu("");
  99.       String title = ((Applet)this).getParameter("frame_title");
  100.       if (title == null) {
  101.          title = "Menu";
  102.       }
  103.  
  104.       this.frame = new Win(title, this);
  105.       this.frame.setBounds(this.frameX, this.frameY, this.frameWidth, this.frameHeight);
  106.       this.frame.setMenuBar(this.pop);
  107.       this.frame.setVisible(true);
  108.       if (this.sound != null) {
  109.          if (this.loopSound) {
  110.             this.sound.loop();
  111.          } else {
  112.             this.sound.play();
  113.          }
  114.       }
  115.  
  116.       ((Component)this).repaint();
  117.    }
  118.  
  119.    public Menu giveMenu(String prof) {
  120.       Menu menu = new Menu(((Applet)this).getParameter("text" + prof));
  121.       int i = 0;
  122.  
  123.       while(true) {
  124.          ++i;
  125.          String prof2 = prof + "#" + Integer.toString(i);
  126.          if (((Applet)this).getParameter("text" + prof2) == null) {
  127.             return menu;
  128.          }
  129.  
  130.          String s = ((Applet)this).getParameter("text" + prof2 + "#1");
  131.          if (s == null) {
  132.             s = ((Applet)this).getParameter("text" + prof2);
  133.             if (s.equals("-")) {
  134.                if (prof.equals("")) {
  135.                   this.pop.add(new Menu("---"));
  136.                } else {
  137.                   menu.addSeparator();
  138.                }
  139.             } else {
  140.                MenuItem menuitem = new MenuItem(((Applet)this).getParameter("text" + prof2));
  141.                menuitem.addActionListener(this);
  142.                menuitem.setActionCommand(((Applet)this).getParameter("link" + prof2));
  143.                if (prof.equals("")) {
  144.                   this.pop.add(new Menu(((Applet)this).getParameter("text" + prof2)));
  145.                } else {
  146.                   menu.add(menuitem);
  147.                }
  148.             }
  149.          } else if (prof.equals("")) {
  150.             this.pop.add(this.giveMenu(prof2));
  151.          } else {
  152.             menu.add(this.giveMenu(prof2));
  153.          }
  154.       }
  155.    }
  156.  
  157.    public void getParameters() {
  158.       this.field_0 = ((Component)this).getSize().width;
  159.       this.field_1 = ((Component)this).getSize().height;
  160.       String s = ((Applet)this).getParameter("frame_width");
  161.       if (s != null) {
  162.          this.frameWidth = Integer.parseInt(s);
  163.       }
  164.  
  165.       s = ((Applet)this).getParameter("frame_height");
  166.       if (s != null) {
  167.          this.frameHeight = Integer.parseInt(s);
  168.       }
  169.  
  170.       s = ((Applet)this).getParameter("frame_X");
  171.       if (s != null) {
  172.          this.frameX = Integer.parseInt(s);
  173.       }
  174.  
  175.       s = ((Applet)this).getParameter("frame_Y");
  176.       if (s != null) {
  177.          this.frameY = Integer.parseInt(s);
  178.       }
  179.  
  180.       s = ((Applet)this).getParameter("sound_name");
  181.       if (s != null) {
  182.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  183.       }
  184.  
  185.       s = ((Applet)this).getParameter("loop_sound");
  186.       if (s != null) {
  187.          if (s.equals("yes")) {
  188.             this.loopSound = true;
  189.          } else {
  190.             this.loopSound = false;
  191.          }
  192.       }
  193.  
  194.       s = ((Applet)this).getParameter("clic_sound_name");
  195.       if (s != null) {
  196.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  197.       }
  198.  
  199.       ((Component)this).setBackground(this.getColor("background_color"));
  200.    }
  201.  
  202.    public Color getColor(String param) {
  203.       String s = ((Applet)this).getParameter(param);
  204.       if (s != null) {
  205.          if (s.substring(0, 1).equals("#")) {
  206.             s = s.substring(1);
  207.             int i = Integer.parseInt(s, 16);
  208.             return new Color(i);
  209.          } else {
  210.             return null;
  211.          }
  212.       } else {
  213.          return null;
  214.       }
  215.    }
  216.  
  217.    public void actionPerformed(ActionEvent evt) {
  218.       if (((EventObject)evt).getSource() instanceof MenuItem) {
  219.          if (this.clicSound != null) {
  220.             this.clicSound.play();
  221.          }
  222.  
  223.          String target = ((Applet)this).getParameter("target");
  224.          if (target == null) {
  225.             target = "_blank";
  226.          }
  227.  
  228.          URL u = this.giveURL(((MenuItem)((EventObject)evt).getSource()).getActionCommand());
  229.          ((Applet)this).getAppletContext().showDocument(u, target);
  230.       }
  231.  
  232.    }
  233.  
  234.    public void stop() {
  235.       if (this.sound != null) {
  236.          this.sound.stop();
  237.       }
  238.  
  239.       this.frame.dispose();
  240.    }
  241.  
  242.    public URL giveURL(String url) {
  243.       try {
  244.          if (url.toUpperCase().startsWith("HTTP")) {
  245.             return new URL(url);
  246.          } else if (url.toUpperCase().startsWith("FTP")) {
  247.             int p = url.indexOf(":");
  248.             int p2 = url.indexOf(":", p + 1);
  249.             if (p2 != -1) {
  250.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  251.             }
  252.  
  253.             p = url.indexOf("%40");
  254.             if (p != -1) {
  255.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  256.             }
  257.  
  258.             return new URL(url);
  259.          } else {
  260.             return new URL(((Applet)this).getCodeBase(), url);
  261.          }
  262.       } catch (MalformedURLException e) {
  263.          System.out.println(e);
  264.          return null;
  265.       }
  266.    }
  267. }
  268.